import cacheKeys from '@/common/app/cacheKeys.js'
import { localStorage } from '@/common/app/storage.js'

export default {
  state: {
    // 缓存系统菜单
    systemMenu: localStorage.getObject(cacheKeys.CACHE_SYSTEM_MENU) || [],
    // 缓存系统菜单数组
    systemMenuArray: localStorage.getObject(cacheKeys.CACHE_SYSTEM_MENU_ARRAY) || []
  },
  getters: {
    systemMenu(state) {
      return state.systemMenu
    },
    systemMenuArray(state) {
      return state.systemMenuArray
    }
  },
  mutations: {
    [cacheKeys.CACHE_SYSTEM_MENU](state, data) {
      state.systemMenu = data;
      localStorage.setObject(cacheKeys.CACHE_SYSTEM_MENU, data)
      if (data === undefined || data === null || data === '') {
        localStorage.removeItem(cacheKeys.CACHE_SYSTEM_MENU)
      }
    },
    [cacheKeys.CACHE_SYSTEM_MENU_ARRAY](state, data) {
      state.systemMenuArray = data;
      localStorage.setObject(cacheKeys.CACHE_SYSTEM_MENU_ARRAY, data)
      if (data === undefined || data === null || data === '') {
        localStorage.removeItem(cacheKeys.CACHE_SYSTEM_MENU_ARRAY)
      }
    }
  }
}
